import { configureStore } from '@reduxjs/toolkit'
import user from '@/store/reducers/user'
import { combineReducers } from 'redux'
import { persistReducer, persistStore } from 'redux-persist'
import storage from 'redux-persist/lib/storage'

const reduces = combineReducers({
  user
})
// 定义持久化配置
const persistConfig = {
  key: 'root',
  storage
  // blacklist:['loading']  //设置某个reducer数据不持久化
}
const persistedReducer = persistReducer(persistConfig, reduces)

const store = configureStore({
  reducer: persistedReducer,
  //解决序列化问题
  middleware: getDefaultMiddleware =>
    getDefaultMiddleware({
      //关闭redux序列化检测
      serializableCheck: false
    })
})
const persistor = persistStore(store)

export { store, persistor }

export type RootState = ReturnType<typeof store.getState>
export type AppDispatch = typeof store.dispatch
